package com.potenza.edu.media.exception;


import com.potenza.edu.media.utils.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.lang.reflect.UndeclaredThrowableException;

@RestControllerAdvice//Advice 通知  AOP
@Component
public class MediaExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共Exception异常处理类");
        return new Result(false,"0",e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result runtimeException(RuntimeException e){
        e.printStackTrace();

        System.out.println("调用了公共异常RuntimeException处理类");
        return new Result(false,"0",e.getMessage());
    }

   @ExceptionHandler(UndeclaredThrowableException.class)
    public Result runtimeException(UndeclaredThrowableException e){
        e.printStackTrace();
        System.out.println("调用了公共异常UndeclaredThrowableException处理类");
       return new Result(false,"0",e.getMessage());
    }
}
